Web Services

Delete an Existing Record Using External Web Service

Description
This customization shows how to use a web service to delete data from a web service-based data source. This provides an alternate way to access data than the database stored procedure and inline SQL normally generated by Iron Speed Designer.
Variables
Table Name
Select the database table
Primary Key
Select the primary key field in the table
Applies to
SQLAccessClass class
Code
 
''' 
''' Deletes a record from the table.
''' 
''' The table to delete from.
''' Nothing, or a filter that restricts which records get deleted.
''' Nothing, or the specific sort order in which the records get deleted.
''' The zero-based index of the first record to delete.
''' The exact number of records to delete.
''' The total number of matching records (ignoring page boundaries).
Public Overrides Sub DeleteRecords(ByVal table As BaseClasses.Data.TableDefinition, _
    ByVal filter As BaseClasses.Data.BaseFilter, _
    ByVal sortOrder As BaseClasses.Data.OrderBy, _
    ByVal startIndex As Integer, ByVal count As Integer, ByRef totalCount As Integer)

    ' If we are deleting using a primary key, then
    ' just call the web service that deletes one record.
    If Not filter Is Nothing AndAlso _
        TypeOf filter Is PrimaryKeyValueFilter Then
        Dim ${Primary Key} As Integer = Get${Primary Key}FromFilter(filter)

        ' Instantiate the object that will communicate with a web service.
        ' Replace "MyWebServiceForTableAccess" with the external web service name
        Dim webService As New localhost.MyWebServiceForTableAccess
        webService.Credentials = System.Net.CredentialCache.DefaultCredentials

        ' Call the web service's "DeleteRecord" function.
        webService.Delete${${Table Name}RecordClassName}(${Primary Key})
        totalCount = 1
        Return
    End If

    ' Else use the normal path to delete records, e.g. using stored procedures, or inline SQL.
    ' You can customize this to call your web service instead.
    MyBase.DeleteRecords(table, filter, sortOrder, startIndex, count, totalCount)
    
End Sub
 
Applies to
SQLAccessClass class
Code
 
''' 
''' Given filter, get the ${Primary Key}.
''' 
Public Function Get${Primary Key}FromFilter( _
        ByVal filter As BaseClasses.Data.BaseFilter) As Integer
    
    ' Define a primary key value filter.
    Dim pkFilter As BaseClasses.Data.PrimaryKeyValueFilter 
    pkFilter = CType(filter, BaseClasses.Data.PrimaryKeyValueFilter)
    
    ' Get the primary key.
    Dim myPrimaryKey As BaseClasses.Data.KeyValue = pkFilter.Value
    Dim ${Table Name}Acc As ${${Table Name}ClassName} = ${${Table Name}ClassName}.Instance
    
    Dim ${Primary Key} As Integer 
    ${Primary Key} = myPrimaryKey.GetColumnValue( _
        ${Table Name}Acc.${Primary Key}Column).ToInt32()
    Return ${Primary Key}
End Function
     

Terms of Service Privacy Statement